﻿@model Inovout.Kuajing.Exports.Console.Web.Models.ExporterInfo
@{
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
@section styles {
    <link href="~/Content/themes/base/autocomplete.css" rel="stylesheet" />
    <style>
        .form form {
            margin: 20em auto;
        }
    </style>
}

@section scriptsHead {
    <script>
        function getUrlParameter(sParam) {
            debugger;
            var sPageURL = window.location.search.substring(1);
            var sURLVariables = sPageURL.split('&');
            for (var i = 0; i < sURLVariables.length; i++) {
                var sParameterName = sURLVariables[i].split('=');
                if (sParameterName[0] == sParam) {
                    return sParameterName[1];
                }
            }
        }
        var phone=getUrlParameter("phone")
        if (phone) {
            $.validator.setDefaults({ ignore: "" });
        }
     
        $(document).ready(function () {

            if (!$("#CommpanyCode").val()) {
                $("#CommpanyCode").val(0);
            }

            if (!$("#OrderPersonCode").val()) {
                $("#OrderPersonCode").val(0);
            }

            $("#CommpanyName").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '@Url.Action("FilterOrganiziation", "OrganizationUnit")',
                        type: "POST",
                        dataType: "json",
                        data: { term: request.term },
                        success: function (data) {
                            response($.map(data, function (item) {
                                return {
                                    label: item.label,
                                    value: item.value
                                };
                            }))
                        }
                    })
                },
                focus: function (event, ui) {
                    $("#CommpanyName").val(ui.item.label);
                    return false;
                },
                minLength: 2,
                select: function (event, ui) {
                    $("#CommpanyName").val(ui.item.label);
                    $("#CommpanyCode").val(ui.item.value);
                    $("#hdCommanyName").val(ui.item.label);
                    return false;
                }
            });


            $("#OrderPersonName").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '@Url.Action("FilterEmployee", "Employee")',
                        type: "POST",
                        dataType: "json",
                        data: { term: request.term, Id: $("#CommpanyCode").val() },
                        success: function (data) {
                            response($.map(data, function (item) {
                                return {
                                    label: item.label,
                                    value: item.value,
                                    phone: item.phone,
                                    tel: item.telPhone
                                };
                            }))

                        }
                    })
                },
                focus: function (event, ui) {
                    $("#OrderPersonName").val(ui.item.label);
                    return false;
                },
                minLength: 2,
                select: function (event, ui) {
                    $("#OrderPersonName").val(ui.item.label);
                    $("#OrderPersonCode").val(ui.item.value);
                    $("#Phone").val(ui.item.phone);
                    $("#TelPhone").val(ui.item.tel);
                    return false;
                }
            });

            //$("#export").on("click", function () {
            //   //var a= $(".form-group").valid();
            //   alert(1);
            //   return false;//
            //});


            //$("#CommpanyName").on("blur", function () {
            //    var hdName = $("#hdCommanyName").val();
            //    if (hdName) {
            //        if (hdName != $("#CommpanyName").val()) {
            //            var $span = $(this).parent("div").find("span");
            //            $span.text("not same");
            //            $span.addClass("has-erro");
            //            $span.addClass("CommpanyName-error");
            //            $span.show();
            //        } else {
            //            return false;
            //        }
            //    }
            //})
        });
    </script>

}


<div>    
     @using (Html.BeginForm("LocateExporter", "TraditionalOrder", FormMethod.Post, new { @class = "form-horizontal exportForm" }))
     {
        @Html.ValidationSummary(true)
        <div class="form-group">
            @Html.LabelFor(model => model.CommpanyName, "公司名称", new { @for = "CommpanyName", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.CommpanyName, new { @placeholder = "南京三宝", @class = "form-control" })
                @Html.HiddenFor(model => model.CommpanyCode, new { @value = "0" })
                @Html.HiddenFor(model => model.CommpanyName, new { @id = "hdCommanyName" })
                @Html.HiddenFor(model => model.orderId)
                @Html.ValidationMessageFor(model => model.CommpanyName)
                @{
         if (Request.QueryString["phone"] != null)
         {
                    @Html.HiddenFor(model => model.CommpanyCompareName, new { @id = "hdCommpanyCompareName" })
                    @Html.ValidationMessageFor(model => model.CommpanyCompareName)
         }                    
                }
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.OrderPersonName, "下单人", new { @for = "OrderPersonName", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.OrderPersonName, new { @placeholder = "jone", @class = "form-control" })
                @Html.HiddenFor(model => model.OrderPersonCode, new { @value = "0" })
                @Html.ValidationMessageFor(model => model.OrderPersonName)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Phone, "手机", new { @for = "Phone", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.Phone, new { @placeholder = "1358768900", @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Phone)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.TelPhone, "固定电话", new { @for = "TelPhone", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.TelPhone, new { @placeholder = "025-8897655", @class = "form-control" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="submit" id="export" class="btn btn-default" value="下单" />
            </div>
        </div>
     }

</div>

